<template>
  <div>
    <h1>会员登录</h1>
    <table class="table">
      <tbody>
        <tr>
          <td>会员名</td>
          <td>
            <input type="text" v-model="data.name" />
          </td>
        </tr>
        <tr>
          <td>会员名</td>
          <td>
            <input type="password" v-model="data.pwd" />
          </td>
        </tr>
        <tr>
          <td>
            <input type="button" value="登录" @click="login" />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useMemberStore } from '@/stores/member';

const users = useMemberStore()

const router=useRouter()

const data=ref({
    name:'',
    pwd:''
})

const login=()=>{
    axios.get('https://localhost:7114/api/Member/Login',{params:data.value}).then(res=>{
        if(res.data.id==-1){
            alert('用户不存在')
            return
        }
        if(res.data.id==-2){
            alert('密码错误')
            return
        }
        if(res.data.id>0){
            alert('登陆成功')
            router.push({path:'/'})
            users.member.name=data.value.name
            users.member.state=true
        }
    })
}

</script>

<style scoped></style>
